package com.itheima.d2_ScheduleDemo;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
 */
public class ScheduleDemo {
    public static void main(String[] args) {
        // 创建ScheduleExecturorService
        ScheduledExecutorService pool = new ScheduledThreadPoolExecutor(3);
        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"AAA执行-次");
            }
        }, 0, 2, TimeUnit.SECONDS);

        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println(10/0);
                System.out.println(Thread.currentThread().getName()+"BBB执行-次");
            }
        },0,2,TimeUnit.SECONDS);
    }
}
